<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>  
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同方案列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<input type="hidden" id="id" value="${prjContCfgVO.id }" />
	<input type="hidden" id="cfgInsCode"/>
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="基础信息" id="tabAId" lselected="true">
			<form id="form1">
				
				<div class="fieldset1 tabel_col clearFix">
					<div class="fieldBox col_50">
						<div class="label">合同方案编码</div>
						<div class="field">
							<input name="cfgCd" id="cfgCd" type="text" value="${prjContCfgVO.cfgCd }" class="ui-textbox" validate="{required:true}"/>
						</div>
					</div>
					<div class="fieldBox col_50" >
						<div class="label">支持的事业部</div>
						<div class="field">
							<input name="orgCd" id="orgCd" type="text" value="${prjContCfgVO.orgCd }" ltype="combobox" validate="{required:true}" placeholder="请选择" />
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">合同方案名称</div>
						<div class="field">
							<input name="cfgNm" id="cfgNm" type="text" value="${prjContCfgVO.cfgNm }" class="ui-textbox" validate="{required:true}"/>
						</div>
					</div>
					<div class="fieldBox col_50" >
						<div class="label">支持的项目类型</div>
						<div class="field">
							<input type="text" id="prjTypCd" name="prjTypCd" value="${prjContCfgVO.prjTypCd }" ltype="combobox" placeholder="请选择" validate="{required:true}"/>
						</div>
					</div>
					<div class="fieldBox col_50" >
						<div class="label">第三方机构</div>
						<div class="field">
							<input type="text" id="insCode" name="insCode" value="${prjContCfgVO.insCode }" ltype="combobox" placeholder="请选择"/>
						</div>
					</div>
					<div class="fieldBox col_100">
						<div class="label">备注</div>
						<div class="field">
							<textarea name="remark" id="remark" rows="4"
									  class="ui-textarea l-textarea" style="width: 80%" value="${prjContCfgVO.remark }" validate="{required:true}" >${prjContCfgVO.remark }</textarea>
						</div>
					</div>
				</div>
			</form>
			<div class="btnsBox">
				<span id="addBtn"  class="sq-button sq-button-round" onclick="save()">保存</span>
			</div>
		</div>
		<div tabid="tabB" title="合同选择" id="tabBId">
			<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
	</div>
</div>

<script type="text/javascript">

	//var prjTypCdCombox;

    $(function () {
       init();
       initForm();
       initTab();
    });

	function init(){
		// 事业部选择框
		orgCdCombox = $("#orgCd").ligerComboBox({
							url:'<%=path%>/system/sysdictionary/getSysDic.do',
							ajaxType:'GET',
							parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"SYS0031" ,useDesc:"true"},
							valueField: 'key',
							textField:'value',
							//value:$("#orgCd").val(),
							onChangeValue: function (newvalue){ // 联动
								var val = this.getValue();
								$("#prjTypCd").ligerComboBox({
									url:'<%=path%>/system/sysdictionary/getSysDic.do',
									ajaxType:'GET',
									parms:{ orgCd: val, sysCd: "11000",codeGroup:"PRJ0002" },
									isShowCheckBox: true, 
						    		isMultiSelect: true,
									valueField: 'key',
									textField:'value'
								}); 
							}
						});
		if($("#orgCd").val()){
			console.log(orgCdCombox);
			orgCdCombox.selectValue($("#orgCd").val());
		}

		// 项目类型
		prjTypCdCombox = $("#prjTypCd").ligerComboBox({
							url:'<%=path%>/system/sysdictionary/getSysDic.do',
							ajaxType:'GET',
							parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"PRJ0002" },
							isShowCheckBox: true, 
				    		isMultiSelect: true,
				    		//value:$("#prjTypCd").val(),
							valueField: 'key',
							textField:'value'
						}); 
		
		
		// 第三方机构
		insCodeComBox = $("#insCode").ligerComboBox({
							url:'<%=path%>/system/sysdictionary/getInsCode.do',
							parms:{ orgCd: "0000", sysCd: "11000"},
							ajaxType:'GET',
							//value:$("#insCode").val(),
							valueField: 'key',
							textField:'value'
						});

		if($("#prjTypCd").val()){
			prjTypCdCombox.selectValue($("#prjTypCd").val());
		}
		if($("#insCode").val()){
			insCodeComBox.selectValue($("#insCode").val());
		}
	}

	function initForm(){
		form1 = $("#form1").ligerForm({
			validate: true
		});
	};

	//初始化Tab
	function initTab(){
		pageInTab = $("#pageInTab").ligerTab({
			height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
			onBeforeSelectTabItem: function (tabid){
				console.log(tabid);
				if("tabB" == tabid){
					if(!$("#id").val()){
						return false;
					} 
					pageInTab.setTabItemSrc(tabid, "<%=path%>/cont/prj/toDtlListPage.do?cfgCd="+$("#cfgCd").val());
				}
		    }
		});

	};

	function save() {
		// form 必填校验
		//var form1 = $("#form1").ligerForm();
		if (!form1.valid()) {
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return;
		}
		var formData = form1.getData();
		var dataId = $("#id").val();
		var reqUrl;
		if(dataId){
			formData.id=dataId;
			reqUrl = '<%=path%>/cont/prj/modify.do'
		}else{
			reqUrl = '<%=path%>/cont/prj/add.do'
		}

		var wait_dialog;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:formData,
			url: reqUrl,
			beforeSend: function () {
				wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					if(!dataId){
						$("#id").val(msg.data);
						$("#cfgInsCode").val($("#insCode").val());
					}
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
				}else{
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},
			error:function () {
				wait_dialog.close();
				top.$.ligerDialog.SQalert({content: "系统错误，请稍后重试",SQ_type: "error"});
			}
		});

	}

</script>

</body>
</html>